
Outpost2 CLM file format
------------------------

Offset 	Size 			Description
------ 	---- 			-----------
0x0	28 (0x1C)		"OP2 Clump File Version 1.0", 0x1A, 0 (Case Insensitive compare?)
0x1C	4			0x00000000 (Alignment?)
0x20	18 (0x12)		WAVEFORMATEX structure
 0x20	2			 WAVEFORMATEX.wFormatTag 	= 1	(WAVE_FORMAT_PCM)
 0x22	2			 WAVEFORMATEX.nChannels 	= 1	(mono)
 0x24	4			 WAVEFORMATEX.nSamplesPerSec 	= 22050 (22.05 KHz)
 0x28	4			 WAVEFORMATEX.nAvgBytesPerSec		(44.1 bytes/sec = nSamplesPerSec*nBlockAlign)
 0x2C	2			 WAVEFORMATEX.nBlockAlign 	= 2	(2 bytes/sample = nChannels*wBitsPerSample/8)
 0x2E	2			 WAVEFORMATEX.wBitsPerSample		(16 bits per sample)
 0x30	2			 WAVEFORMATEX.cbSize			(0 = Size of format data following WAVEFORMATEX structure)
0x32	2			0x00 (Alignment?)
0x34	4			trackSizeAlignment? (65536?) (abs of this value must be 0 mod 65536)
0x38	4			numPackedFiles
0x3C	16*numPackedFiles	IndexEntry[] - table of index entries describing all files stored in the archive
	 8			 FileName - Internal file name
	 4			 Offset - offset to file data
	 4			 Size - size of stored file data
0x3C+16*numPackedFiles		Raw file data


Note: The size of each file should be a multiple of 0x8000 (32768) to prevent glitches when Outpost2 is switching between tracks. This is due to the way the sound buffer is filled in multiples of 0x8000 bytes, and no zero filling occurs if the last file read was a bit short. Playback of the next track begins at the next 0x8000 byte boundary.
Note: All the file sizes currently in the .CLM file are actually multiples of 0x10000, which is the size of the sound buffer used for the music. However, only half of the buffer is filled at a time to prevent glitches with the currently playing sound, so a file size that is a multiple of 0x8000 is sufficient to prevent glitches during track changes.



Loading Notes
-------------

Outpost2.exe reads the first 0x46 (76) bytes of the file and processes it. 
Eventually, the total size of the file header is calculated and the already
read data is copied to the new buffer and then the rest is read in from the
file. (The IndexEntry[] array is included in this data.)

The header string is first verified ("OP2 Clump File Version 1.0", 0x1A, 0)
and reading is aborted if the string does not match. The string compare
function uses a global variable to determine if the compare is case
sensitive. (Or other format conversions?)

The WAVEFORMATEX structure is then checked for validity. The following
fields are checked for the following values:
 WAVEFORMATEX.wFormatTag 	= 1		(WAVE_FORMAT_PCM)
 WAVEFORMATEX.nChannels		= 1		(Mono)
 WAVEFORMATEX.nBlockAlign	= 2		(2 bytes/sample, including both channels - only 1 channel)
 WAVEFORMATEX.nSamplesPerSec	= 22050		(22.05 KHz)

At this point, the total header size is calculated using the numPackedFiles
header entry and memory is allocated to hold the entire header. The data
that was already read in is copied to this buffer and the remaining data is
read in from the file.

A file index table is initilzed. It contains 0x1A (26) entries. All values
are initialized to -1. The table is filled in with the internal CLM file
index of each of the following files. If any of these files do not exist
in the CLM archive, the load is aborted.
 0) "EDEN11"
 1) "EDEN21"
 2) "EDEN22"
 3) "EDEN31"
 4) "EDEN32"
 5) "EDEN33"
 6) "EP41"
 7) "EP42"
 8) "EP43"
 9) "EP51"
 10) "EP52"
 11) "EP61"
 12) "EP62"
 13) "EP63"
 14) "PLYMTH11"
 15) "PLYMTH12"
 16) "PLYMTH21"
 17) "PLYMTH22"
 18) "PLYMTH31"
 19) "PLYMTH32"
 20) "PLYMTH33"
 21) "STATIC01"
 22) "STATIC02"
 23) "STATIC03"
 24) "STATIC04"
 25) "STATIC05"
These files are searched for in a linear order. (Not a binary search, so 
alphabetical order is not required for this check.) Also, there is no
check to exlcude files not in this list from being packed in the CLM
archive.




Layout of Internal Classes
--------------------------


PlayList **TODO** Name this better (DOH! Mixing two seperate objects here **TODO** sort this mess out)
--------


Offset 	Size 	Description
------ 	---- 	-----------
0x0	4	HINSTANCE hDSoundModule - handle of DSOUND.DLL
0x4	4	(counter? Incremented on entry and on exit of routine that initializes DirectSound)
0x8	4	LPDIRECTSOUND lpDS - Direct sound object
0xC	4	LPDIRECTSOUNDBUFFER lpDirectSoundBuffer - Primary sound buffer
0x10	4	
0x14	4	
0x18	4	
0x1C	4	char* headerData - pointer to buffer containing file header
0x20	4	HANDLE fileHandle - handle to the opened CLM file
0x24	4	int totalFileHeaderSize - size of headerData buffer
0x28	4*26	SongIndexTable[] - Contains the index for each of the songs
			whose names are built into Outpose2.exe.
.
.
.

0xC4	4	numPlayListEntries
0xC8	4	??? (param2 of SetMusicPlayList)
0xCC	4	Pointer to buffer ???
0xD0	4	(Initialized to 0)
0xD4	4	(Initialized to 0)


Object #2 **TODO name this better
---------

Offset 	Size 	Description
------ 	---- 	-----------
0x0	4	
0x4	4	
0x8	4	
0xC	4	
0x10	4	
0x14	4	
0x18	4	
0x1C	4	




Sound Initialization Notes
--------------------------
Outpost2.exe will attemp to initialize the buffer format of the primary sound
buffer in the following order.
 1) 
	WAVEFORMATEX.wFormatTag		:= 1 		(WAVE_FORMAT_PCM)
	WAVEFORMATEX.nChannels		:= 2		(Stereo)
	WAVEFORMATEX.nSamplesPerSec	:= 22050	(22.05 KHz)
	WAVEFORMATEX.nAvgBytesPerSec	:= 88200	(88200 bytes/sec)
	WAVEFORMATEX.nBlockAlign	:= 4		(4 bytes/sample, including both channels)
	WAVEFORMATEX.wBitsPerSample	:= 16		(16 bit sound samples)
	WAVEFORMATEX.cbSize		:= 18		(18 bytes following WAVEFORMATEX structure, 

 2) 
	WAVEFORMATEX.wFormatTag		:= 1 		(WAVE_FORMAT_PCM)
	WAVEFORMATEX.nChannels		:= 2		(Stereo)
	WAVEFORMATEX.nSamplesPerSec	:= 22050	(22.05 KHz)
	WAVEFORMATEX.nAvgBytesPerSec	:= 44100	(44100 bytes/sec)
	WAVEFORMATEX.nBlockAlign	:= 2		(2 bytes/sample, including both channels)
	WAVEFORMATEX.wBitsPerSample	:= 8		(8 bit sound samples)
	WAVEFORMATEX.cbSize		:= 18		(18 bytes following WAVEFORMATEX structure, 
							but should be ignored for WAVE_FORMAT_PCM)
 3) 
	WAVEFORMATEX.wFormatTag		:= 1 		(WAVE_FORMAT_PCM)
	WAVEFORMATEX.nChannels		:= 1		(Mono)
	WAVEFORMATEX.nSamplesPerSec	:= 22050	(22.05 KHz)
	WAVEFORMATEX.nAvgBytesPerSec	:= 22050	(22050 bytes/sec)
	WAVEFORMATEX.nBlockAlign	:= 1		(1 bytes/sample, including both channels)
	WAVEFORMATEX.wBitsPerSample	:= 8		(8 bit sound samples)
	WAVEFORMATEX.cbSize		:= 18		(18 bytes following WAVEFORMATEX structure, 
							but should be ignored for WAVE_FORMAT_PCM)
Summary:
 1) Frequency = 22050 Hz, Channels = 2 (Stereo), BitsPerSample = 16
 2) Frequency = 22050 Hz, Channels = 2 (Stereo), BitsPerSample = 8
 3) Frequency = 22050 Hz, Channels = 1 (Mono), BitsPerSample = 8

